﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CaptureVision.Sunflower
{
    

    public class VectorProperty<TVector, TPropertyType> : TypedSunflowProperty<TPropertyType> 
        where TVector : Vec<TPropertyType>, new()
    {
        private TVector                             _vector;
        
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="vector">The vector.</param>
        /// <param name="elementNames">The element names.</param>
        public VectorProperty(string name, TVector vector, params string[] elementNames) : base(name)
        {
            _vector         = vector;
            fillValuesFromParameters(elementNames);
        }

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="vector">The vector.</param>
        /// <param name="elementNames">The element names.</param>
        public VectorProperty(string name, params string[] elementNames) : this(name, new TVector(), elementNames)
        {
        }

        /// <summary>
        /// Fills the values from parameters.
        /// </summary>
        /// <param name="elementNames">The element names.</param>
        protected void fillValuesFromParameters(string[] elementNames)
        {
            if (_vector is IVector1<TPropertyType>)
            {
                _values.Add(elementNames[0], ((IVector1<TPropertyType>)_vector).X);
            }
            if (_vector is IVector2<TPropertyType>)
            {
                _values.Add(elementNames[1], ((IVector2<TPropertyType>)_vector).Y);
            }
            if (_vector is IVector3<TPropertyType>)
            {
                _values.Add(elementNames[2], ((IVector3<TPropertyType>)_vector).Z);
            }
            if (_vector is IVector4<TPropertyType>)
            {
                _values.Add(elementNames[3], ((IVector4<TPropertyType>)_vector).W);
            }
        }


        /// <summary>
        /// Gets or sets the <see cref="TVectorType"/> with the specified element name.
        /// </summary>
        public TPropertyType this[string elementName]
        {
            get
            {
                return _values[elementName];
            }
            set
            {
                _values[elementName] = value;
            }
        }


        /// <summary>
        /// Gets or sets the <see cref="TVectorType"/> with the specified element index.
        /// </summary>
        public TPropertyType this[int elementIndex]
        {
            get
            {
                return _values.Values.ElementAt(elementIndex);
            }
            set
            {
                _values[_values.ElementAt(elementIndex).Key] = value;
            }
        }



       

        /// <summary>
        /// Gets or sets the vector.
        /// </summary>
        public TVector Vector
        {
            get { return _vector; }
            set { _vector = value; }
        }





    }
}
